package exp3;
//实现一个格点类（纵横坐标都是整数），要求在[100X100]的网格内随机生成100个点，按照x坐标排序
import java.util.Arrays;
import java.util.Comparator;
import java.util.Random;

class Point{
    int x,y;

    Point(){
        this(0);
    }
    Point(int x){
        this(x,0);
    }
    Point(int x,int y){
        this.x=x;
        this.y=y;
    }

    @Override
    public String toString() {
        return String.format("%d,%d",this.x,this.y);
    }
}

public class PointApp {
    public static void main(String[] args) {
        Random random = new Random();
        Point[] points = new Point[100];
        for(int i=0;i<points.length;i++){
            int x = random.nextInt(100);
            int y = random.nextInt(100);
            points[i] = new Point(x,y);
        }
        Arrays.sort(points, new Comparator<Point>() {
            @Override
            public int compare(Point o1, Point o2) {
                return o1.x-o2.x;
            }
        });

        for (Point point: points) {
            System.out.println(point);
        }
    }
}

